package cn.fl.product.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DecimalUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.cmm.cache.framework.utils.PropertiesCacheUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.product.service.IPrdBscInfoService;
import cn.fl.product.service.IPrdTkInfoService;
import cn.fl.product.vo.PrdBscInfoVO;
import cn.fl.product.vo.PrdTkInfoVO;
import cn.fl.system.constant.SysLogConstant;

import com.alibaba.fastjson.JSONObject;

import fl.flow.facade.flow.constant.FlowConstant;
import fl.product.facade.product.condition.PrdTkInfoQueryCondition;

/**
 * @Description: 卡车产品信息表 控制层
 */
@Controller
@RequestMapping("/product/prdTkInfo")
public class PrdTkInfoController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(PrdTkInfoController.class);

	/**
	 * PrdTkInfo 服务层BEAN
	 */
	@Autowired
	private IPrdTkInfoService prdTkInfoService;
	
	/**
	 * 产品进本信息服务
	 */
	@Autowired
	private IPrdBscInfoService prdBscInfoService;
	
	@Autowired
	private ISysDictionaryApiService sysDictionaryApiService;

	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET})
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		String prdId = request.getParameter("prdId");
		ModelAndView view = new ModelAndView("product/prdTkInfo/prdTkInfoList");
		BaseLogUtils.info(logger, "toListPage", "跳转到列表页面.", CurrentThreadContext.getCurrentUserName());
		view.addObject("prdId", prdId);
		return view;
	}

	/**
	 * 到新增/修改页面
	 */
	@RequestMapping(value = "/toAddPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toAddPage(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		String prdId = request.getParameter("prdId");
		
		//用来刷新页面动态字段
		String bizTypCd = request.getParameter("bizTypCd");//目标代码组值(业务类型代码)
		String bizCd = request.getParameter("bizCd");//目标代码值(业务代码)
		//用来获取下拉框动态数据
		String sGrpCd = request.getParameter("sGrpCd");//源代码组值
		String sCode = request.getParameter("sCode");//源代码值
		
		ModelAndView view = new ModelAndView("product/prdTkInfo/prdTkInfoAdd");
		view.addObject("id", id);
		view.addObject("prdId", prdId);
		view.addObject("bizTypCd", bizTypCd);
		view.addObject("bizCd", bizCd);
		view.addObject("sGrpCd", sGrpCd);
		view.addObject("sCode", sCode);
		BaseLogUtils.info(logger, "toModifyPage", "跳转到新增页面.", CurrentThreadContext.getCurrentUserName());
		
		String isShowAuditBtn = request.getParameter("isShowAuditBtn");
		view.addObject("isShowAuditBtn", isShowAuditBtn);
		
		view.addObject("currBuOrgCd", CurrentThreadContext.getCurrentBuOrgCd());
		
		//燃料种类
		List<KeyValueVO> fuelTypCdKvList = new ArrayList<>();
		List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(),
				PropertiesCacheUtils.getProperty(fl.constant.facade.framework.constant.DictionaryConstant.FUEL_TYP_CD));
		if (CollectionUtils.isNotEmpty(sysDictionaryDTOList)) {
			for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
				KeyValueVO keyValueVO = new KeyValueVO();
				keyValueVO.setKey(sysDictionaryDTO.getCode());
				keyValueVO.setValue(sysDictionaryDTO.getCodeNm());
				fuelTypCdKvList.add(keyValueVO);
			}
		}
		view.addObject("fuelTypCdList", fuelTypCdKvList);
		return view;
	}
	/**
	 * 到新增/修改页面
	 */
	@RequestMapping(value = "/toDetailPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toDetailPage(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		String prdId = request.getParameter("prdId");
		
		//用来刷新页面动态字段
		String bizTypCd = request.getParameter("bizTypCd");//目标代码组值(业务类型代码)
		String bizCd = request.getParameter("bizCd");//目标代码值(业务代码)
		//用来获取下拉框动态数据
		String sGrpCd = request.getParameter("sGrpCd");//源代码组值
		String sCode = request.getParameter("sCode");//源代码值
		
		ModelAndView view = new ModelAndView("product/prdTkInfo/prdTkInfoDetail");
		view.addObject("id", id);
		view.addObject("prdId", prdId);
		view.addObject("bizTypCd", bizTypCd);
		view.addObject("bizCd", bizCd);
		view.addObject("sGrpCd", sGrpCd);
		view.addObject("sCode", sCode);
		BaseLogUtils.info(logger, "toDetailPage", "跳转到详情页面.", CurrentThreadContext.getCurrentUserName());
		return view;
	}
	
	/**
	 * 到动态字段组件页面
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/toTkDynamicFldPage.do", method = { RequestMethod.GET,RequestMethod.POST })
	public ModelAndView toDynamicBizPage(HttpServletRequest request, HttpServletResponse response) {
		String bizTypCd = request.getParameter("bizTypCd");
		String bizCd = request.getParameter("bizCd");
		
		ModelAndView view = new ModelAndView("product/prdTkInfo/prdTkInfoAddDynamicPage");
		if(StringUtils.isNotEmpty(bizTypCd) && StringUtils.isNotEmpty(bizCd)){
			view.addObject("bizTypCd", bizTypCd);
			view.addObject("bizCd", bizCd);
		}else{
			view.addObject("bizTypCd", "");
			view.addObject("bizCd", "");
		}
		return view;
	}
	/**
	 * 到动态字段组件页面
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/toTkDynamicFldDetailPage.do", method = { RequestMethod.GET,RequestMethod.POST })
	public ModelAndView toDynamicBizDetailPage(HttpServletRequest request, HttpServletResponse response) {
		String bizTypCd = request.getParameter("bizTypCd");
		String bizCd = request.getParameter("bizCd");
		
		ModelAndView view = new ModelAndView("product/prdTkInfo/prdTkInfoDetailDynamicPage");
		if(StringUtils.isNotEmpty(bizTypCd) && StringUtils.isNotEmpty(bizCd)){
			view.addObject("bizTypCd", bizTypCd);
			view.addObject("bizCd", bizCd);
		}else{
			view.addObject("bizTypCd", "");
			view.addObject("bizCd", "");
		}
		return view;
	}

	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String prdId = request.getParameter("prdId");
		Pager page = new Pager();
		if(StringUtils.isEmpty(prdId)){
			ListPageVO<PrdTkInfoVO> listPage = new ListPageVO<PrdTkInfoVO>(new ArrayList<PrdTkInfoVO>(), 0);
			return listPage;
		}
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		PrdTkInfoQueryCondition qc = new PrdTkInfoQueryCondition();
		qc.setPrdId(Long.valueOf(prdId));
		page.setCondition(qc);

		Pager pager = this.prdTkInfoService.searchListPage(page);
		List<PrdTkInfoVO> list = (List<PrdTkInfoVO>) pager.getResultList();
		ListPageVO<PrdTkInfoVO> listPage = new ListPageVO<PrdTkInfoVO>(list, pager.getTotalCount());
		BaseLogUtils.info(logger, "initList", "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}

	/**
	 * 删除数据
	 */
	@RequestMapping(value = "/removeByIds.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String ids = request.getParameter("ids");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
		if(StringUtils.isEmpty(ids)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			return result;
		}
		List<Long> idsList = new ArrayList<Long>();
		JSONArray idsArray = JSONArray.fromObject(ids);
		for (Object object : idsArray) {
			idsList.add(Long.valueOf(object.toString()));
		}
		try {
			boolean success = this.prdTkInfoService.removeByIds(idsList);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_DELETE_FAIL);
				BaseLogUtils.info(logger, "removeById", "删除数据失败,ID:"+ids, CurrentThreadContext.getCurrentUserName());
			}
			BaseLogUtils.info(logger, "removeById", "删除数据.[id="+ids+"]", CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "removeById", "删除数据失败.[id="+ids+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "removeById", "删除数据失败.[id="+ids+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}

		return result;
	}

	/**
	 * 得到一条记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.error(logger, "getById", "获取数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		
		try {
			PrdTkInfoVO vo = this.prdTkInfoService.selectById(Long.valueOf(id));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
				BaseLogUtils.info(logger, "getById", "获取数据,数据不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			}
			result.setData(vo);
			BaseLogUtils.info(logger, "getById", "获取数据.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getById", "获取失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "getById", "获取失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}

	/**
	 * 新增
	 */
	@RequestMapping(value = "/add.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object add(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		PrdTkInfoVO entity = new PrdTkInfoVO();
		try {
			entity = this.getRequestParamForPrdTkAdd(request);
			Long id = this.prdTkInfoService.add(entity);
			result.setData(id);
			BaseLogUtils.info(logger, "add", "新增数据.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "add", "新增数据失败.DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "add", "新增数据失败.DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}

		return result;
	}

	/**
	 * 修改
	 */
	@RequestMapping(value = "/modify.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modify(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "modify", "修改数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		PrdTkInfoVO entity = new PrdTkInfoVO();
		try {
			entity = this.getRequestParamForPrdTkModify(request);
			entity.setId(Long.valueOf(id));
			boolean success = this.prdTkInfoService.modify(entity);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
				BaseLogUtils.info(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
			}
			BaseLogUtils.info(logger, "modify", "修改成功.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	/**
	 * 启用卡车信息
	 */
	@RequestMapping(value = "/enable.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object enable(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES,SysLogConstant.LOG_CMM_ENABLE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "enable", "启用卡车信息失败,主键参数为空.", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		PrdTkInfoVO prdTkInfoVO = new PrdTkInfoVO();
		prdTkInfoVO.setId(Long.valueOf(id));
		//启用
		prdTkInfoVO.setIsValid(BaseConstant.IS_YESNO_YES);
		try {
			boolean success = this.prdTkInfoService.modifyEnAblePrdTkInfo(prdTkInfoVO);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_ENABLE_FAIL);
			}
			BaseLogUtils.info(logger, "enable", "启用卡车信息,ID:"+id, CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "enable", "启用卡车信息失败,ID:"+id+".ERROR:"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "enable", "启用卡车信息失败,系统错误.ID:"+id+".ERROR:"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	/**
	 * 禁用卡车信息
	 */
	@RequestMapping(value = "/disable.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object disable(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES,SysLogConstant.LOG_CMM_DISABLE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "disable", "禁用卡车信息主键参数不存在.", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		PrdTkInfoVO prdTkInfoVO = new PrdTkInfoVO();
		prdTkInfoVO.setId(Long.valueOf(id));
		//禁用
		prdTkInfoVO.setIsValid(BaseConstant.IS_YESNO_NO);
		try {
			boolean success = this.prdTkInfoService.modifyDisAblePrdTkInfo(prdTkInfoVO);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_DISABLE_FAIL);
			}
			BaseLogUtils.info(logger, "disable", "禁用卡车信息,ID:"+id, CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "disable", "禁用卡车信息失败,ID:"+id+".ERROR:"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "disable", "禁用卡车信息失败,系统错误.ID:"+id+".ERROR"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	/**
	 * 到修改审核状态页面
	 */
	@RequestMapping(value = "/toModifyAudStsCdPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toModifyAudStsCdPage(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		BaseLogUtils.info(logger, "toModifyAudStsCdPage", "加载修改审核状态页面.",CurrentThreadContext.getCurrentUserName());
		ModelAndView view = new ModelAndView("product/prdTkInfo/prdModifyAudStsCd");
		//审核状态
		List<KeyValueVO> searchAudStsCdList = this.prdBscInfoService.searchAudStsCdList1();
		view.addObject("searchAudStsCdList", searchAudStsCdList);
		view.addObject("id", id);
		return view;
	}
	/**
	 * 修改审核状态
	 */
	@RequestMapping(value = "/modifyAudStsCd.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO modifyAudStsCd(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		String audStsCd = request.getParameter("audStsCd");
		String id = request.getParameter("id");
		String isSubmit = request.getParameter("isSubmit");
		String prdId = request.getParameter("prdId");
		if(StringUtils.isNotEmpty(isSubmit) || "1".equals(isSubmit)){
			PrdBscInfoVO prdBscInfoVO = this.prdBscInfoService.selectById(Long.valueOf(prdId));
			String audStsCd2 = prdBscInfoVO.getAudStsCd();
			if(FlowConstant.FLOW_CHECK_STATE_NON.equals(audStsCd2)){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("主产品信息未提交,请先提交出产品信息.");
				return result;
			}
		}
		if(StringUtils.isEmpty(id) || StringUtils.isEmpty(audStsCd)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "modifyAudStsCd", "修改审核状态,参数不完整！", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		try {
			boolean success = this.prdTkInfoService.modifyAudStsCd(Long.valueOf(id), audStsCd, new Date(), CurrentThreadContext.getCurrentUserId());
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_OPERATE_FAIL);
			}
			BaseLogUtils.info(logger, "modifyAudStsCd", "修改审核状态,ID:"+id+".audStsCd:"+audStsCd, CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "modifyAudStsCd", "修改审核状态失败,ID:"+id+".audStsCd:"+audStsCd+".ERROR:"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "modifyAudStsCd", "修改审核状态失败,系统错误.ID:"+id+".audStsCd:"+audStsCd+".ERROR:"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}

		return result;
	}
	
	//********************私有方法********************//
	/**
	 * 获取卡车参数信息
	 * @param request
	 * @return
	 * @throws BaseException
	 */
	private PrdTkInfoVO getRequestParamForPrdTk(HttpServletRequest request)throws BaseException{
		String prdId = request.getParameter("prdId");//产品ID
		if (StringUtils.isBlank(prdId)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "产品基本信息ID不能为空.");
		}
		//卡车-主车
		String drvTyp = request.getParameter("drvTyp");//驱动形式
		String engMdl = request.getParameter("engMdl");//发动机型号
		String hp = request.getParameter("hp");//马力
		String cabSpec = request.getParameter("cabSpec");//驾驶室规格
		String grboxMdl = request.getParameter("grboxMdl");//变速箱型号
		String rearAxleSpec = request.getParameter("rearAxleSpec");//后桥规格
		String mWhlSpec = request.getParameter("mWhlSpec");//轮胎规格
		String gasCylSpec = request.getParameter("gasCylSpec");//燃气瓶规格
		String emiStd = request.getParameter("emiStd");//排放标准
		String saddleSpec = request.getParameter("saddleSpec");//鞍座
		String isHvAirCnd = request.getParameter("isHvAirCnd");//是否有空调
		String whlBase = request.getParameter("whlBase");//轴距
		String cntrSz = request.getParameter("cntrSz");//合格证货箱尺寸
		String isHvSub = request.getParameter("isHvSub");//是否上装
		String clsExfPcDouble = request.getParameter("clsExfPcDouble");//底盘出厂价格
		String mOthInfo = request.getParameter("mOthInfo");//主车-其他配置
		
		String seatRowCd = request.getParameter("seatRowCd");//座位排数
		String batDeg = request.getParameter("batDeg");//电池度数
		
		String isNew = request.getParameter("isNew");//是否新车
		String fuelTypCd = request.getParameter("fuelTypCd");//燃料种类
		
		if(StringUtils.isNotEmpty(saddleSpec)){
			if(!StringUtils.isUnsignedNumeric(saddleSpec) || saddleSpec.contains(".")){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "鞍座必须为正整数.");
			}
			if(saddleSpec.contains(".") && saddleSpec.split("\\.")[1].length()>0){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "鞍座必须为正整数.");
			}
		}
		
		//卡车-上装/挂车
		String actCntrSz = request.getParameter("actCntrSz");//货箱(长*宽*高)				0
		String thickness = request.getParameter("thickness");//厚度(底*边)(毫米)			0
		String axleInfo = request.getParameter("axleInfo");//车轴品牌*数量 				0
		String matQalCd = request.getParameter("matQalCd");//板材材质 					0
		String doorInfo = request.getParameter("doorInfo");//开门数及方式					0
		String trlWhlSpec = request.getParameter("trlWhlSpec");//轮胎规格*数量			0
		String cylSepc = request.getParameter("cylSepc");//油缸规格						0
		String othInfo = request.getParameter("othInfo");//其他							0
		String tankVol = request.getParameter("tankVol");//罐体有效容积
		String liftWayCd = request.getParameter("liftWayCd");//举升方式
		String isHvWhl = request.getParameter("isHvWhl");//是否有轮胎
		//String outLen = request.getParameter("outLen");//公告外廓长度
		//String axleQty = request.getParameter("axleQty");//公告车轴数
		String guidePcDouble_tk = request.getParameter("guidePcDouble_tk");//建议价格
		
		
		PrdTkInfoVO prdTkInfoVO = new PrdTkInfoVO();	//卡车信息
		prdTkInfoVO.setPrdId(Long.valueOf(prdId));
		//主车
		prdTkInfoVO.setDrvTyp(drvTyp);
		prdTkInfoVO.setEngMdl(engMdl);
		if(StringUtils.isNotEmpty(hp)){
			prdTkInfoVO.setHp(Long.valueOf(hp));
		}
		prdTkInfoVO.setCabSpec(cabSpec);
		prdTkInfoVO.setGrboxMdl(grboxMdl);
		prdTkInfoVO.setRearAxleSpec(rearAxleSpec);
		prdTkInfoVO.setMWhlSpec(mWhlSpec);
		prdTkInfoVO.setGasCylSpec(gasCylSpec);
		prdTkInfoVO.setEmiStd(emiStd);
		if(StringUtils.isNotEmpty(saddleSpec)){
			prdTkInfoVO.setSaddleSpec(Long.valueOf(saddleSpec));
		}
		if(StringUtils.isNotEmpty(isHvAirCnd)){
			prdTkInfoVO.setIsHvAirCnd(Integer.valueOf(isHvAirCnd));
		}
		prdTkInfoVO.setWhlBase(whlBase);
		prdTkInfoVO.setCntrSz(cntrSz);
		if(StringUtils.isNotEmpty(isHvSub)){
			prdTkInfoVO.setIsHvSub(Integer.valueOf(isHvSub));
		}
		if(StringUtils.isNotEmpty(clsExfPcDouble)){
			prdTkInfoVO.setClsExfPc(DecimalUtils.convertYuanToFen(Double.valueOf(clsExfPcDouble)));
		}
		prdTkInfoVO.setmOthInfo(mOthInfo);
		//上装/挂车
		prdTkInfoVO.setActCntrSz(actCntrSz);
		prdTkInfoVO.setThickness(thickness);
		prdTkInfoVO.setAxleInfo(axleInfo);
		prdTkInfoVO.setMatQalCd(matQalCd);
		prdTkInfoVO.setDoorInfo(doorInfo);
		prdTkInfoVO.setTrlWhlSpec(trlWhlSpec);
		prdTkInfoVO.setCylSepc(cylSepc);
		prdTkInfoVO.setOthInfo(othInfo);
		prdTkInfoVO.setTankVol(tankVol);
		prdTkInfoVO.setLiftWayCd(liftWayCd);
		if(StringUtils.isNotEmpty(isHvWhl)){
			prdTkInfoVO.setIsHvWhl(Integer.valueOf(isHvWhl));
		}
		if(StringUtils.isNotEmpty(guidePcDouble_tk)){
			prdTkInfoVO.setGuidePc(DecimalUtils.convertYuanToFen(Double.valueOf(guidePcDouble_tk)));
		}
		prdTkInfoVO.setSeatRowCd(seatRowCd);
		if(StringUtils.isNotEmpty(batDeg)){
			prdTkInfoVO.setBatDeg(Double.valueOf(batDeg));
		}
		if(StringUtils.isNotEmpty(isNew)){
			prdTkInfoVO.setIsNew(Integer.valueOf(isNew));
		}
		prdTkInfoVO.setFuelTypCd(fuelTypCd);
	
		return prdTkInfoVO;
	}
	
	/**
	 * 获取卡车请求参数(新增)
	 * @param request 请求
	 * @return 
	 */
	private PrdTkInfoVO getRequestParamForPrdTkAdd(HttpServletRequest request)throws BaseException{
		PrdTkInfoVO prdTkInfoVO = this.getRequestParamForPrdTk(request);
		prdTkInfoVO.setCrtTm(new Date());
		prdTkInfoVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
		return prdTkInfoVO;
	}
	
	/**
	 * 获取卡车请求参数(修改)
	 * @param request 请求
	 * @return 
	 */
	private PrdTkInfoVO getRequestParamForPrdTkModify(HttpServletRequest request)throws BaseException{
		PrdTkInfoVO prdTkInfoVO = this.getRequestParamForPrdTk(request);
		prdTkInfoVO.setMdfTm(new Date());
		prdTkInfoVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
		return prdTkInfoVO;
	}
}

